﻿Imports IIC.Forms.Edit

Public Class ucTreeViewPeriodView

    Private Sub tsbGotoClass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbGotoClass.Click

        If Me.UcPeriodClassList.grdPeriodClass.SelectedRows.Count = 0 Then
            winUtils.MsgboxInfo("Please Click on a row in the list below to select it.")
            Exit Sub
        End If

        Dim periodClassId As Integer = Me.UcPeriodClassList.grdPeriodClass.IdValue()
        If Application.OpenForms("frmMain") IsNot Nothing Then
            Dim f As frmMain = CType(Application.OpenForms("frmMain"), frmMain)
            Dim tview As TreeView = f.ucSystemTree.tvMain
            For Each tnd As TreeNode In tview.SelectedNode.Nodes
                If TypeOf (tnd.Tag) Is PeriodClass Then
                    If CType(tnd.Tag, PeriodClass).ClassId = periodClassId Then
                        tview.SelectedNode = tnd
                        Exit Sub
                    End If
                End If

            Next

        End If

    End Sub

    Private Sub tsbEditClass2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                Handles tsbEditClass.Click

        EditClass()

    End Sub

    Private Sub grdPeriodClass_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs)

        EditClass()

    End Sub

    Private Sub EditClass()
        'edit Class
        If Me.UcPeriodClassList.grdPeriodClass.SelectedRows.Count = 0 Then
            winUtils.MsgboxInfo("Please Click on a row in the list below to select it.")
            Exit Sub
        End If

        Dim periodClassId As Integer = Me.UcPeriodClassList.grdPeriodClass.IdValue()

        Using f As New frmPeriodClassDetails

            f.IdValue = periodClassId
            f.LoadData()

            If f.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Me.UcPeriodClassList.grdPeriodClass.loadGrid()
            End If



        End Using
    End Sub

    Private Sub ucTreeViewPeriodView_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        AddHandler UcPeriodClassList.grdPeriodClass.DoubleClick, AddressOf grdPeriodClass_DoubleClick

    End Sub
End Class
